package com.jzqf.compose.navigation

import androidx.compose.runtime.Composable
import androidx.navigation.NavController
import androidx.navigation.NavHostController
import androidx.navigation.NavOptions
import androidx.navigation.compose.NavHost
import com.jzqf.demo.demoScreen
import com.jzqf.home.HOME_ROUTE
import com.jzqf.home.homeScreen
import com.jzqf.mall.mallScreen
import com.jzqf.mine.mineScreen
import com.jzqf.wan.wanScreen

@Composable
fun AppNavHost(
    startDestination: String = HOME_ROUTE,
    navController: NavHostController,
) {
    NavHost(navController = navController, startDestination = startDestination) {
        homeScreen(onNavigateTo = navController::navigateTo)
        mallScreen(onNavigateTo = navController::navigateTo)
        wanScreen(onNavigateTo = navController::navigateTo)
        mineScreen(onNavigateTo = navController::navigateTo)
        demoScreen(onNavigateTo = navController::navigateTo)
    }
}

fun NavController.navigateTo(
    routePath: String, params: String? = null, navOptions: NavOptions? = null
) {
    val route = if (params != null) {
        "${routePath}?${params}"
    } else {
        routePath
    }
    navigate(route, navOptions)
}